package repository;

import android.arch.lifecycle.MutableLiveData;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.util.Log;

import java.util.concurrent.TimeUnit;

import javax.inject.Inject;

import io.reactivex.Observable;
import io.reactivex.Scheduler;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.subscribers.DisposableSubscriber;
import model.redpack.PackListRsp;
import retrofit2.Retrofit;
import retrofit2.mock.MockRetrofit;
import service.RedPackService;


public class RedPackRepository extends BaseRepository{

    Retrofit retrofit;
    MockRetrofit mockRetrofit;

    @Inject
    public RedPackRepository(Retrofit retrofit, MockRetrofit mockRetrofit) {
        this.retrofit = retrofit;
        this.mockRetrofit = mockRetrofit;
    }

    public MutableLiveData<PackListRsp> getRedPackList() {
        final MutableLiveData<PackListRsp> redPackMutableLiveData = new MutableLiveData<>();
       /* mockRetrofit.create(RedPackService.class)
                .returning("")
                .getSearchList(1,1,"id")
                .subscribe(data -> redPackMutableLiveData.setValue(data));*/
        retrofit.create(RedPackService.class)
                .getSearchList(1,2,"id")
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .as(bindLifecycle())
                .subscribe(new DisposableSubscriber<PackListRsp>() {
                    @Override
                    public void onNext(PackListRsp packListRsp) {
                        redPackMutableLiveData.setValue(packListRsp);
                    }

                    @Override
                    public void onError(Throwable t) {
                        t.printStackTrace();
                    }

                    @Override
                    public void onComplete() {

                    }
                });
            return redPackMutableLiveData;
    }
}
